/**
 * Copyright (c) 2009 Teoti Graphix, LLC See:
 *     http://tkarchitecture.teotigraphix.org
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 * 
 * @author Michael Schmalle mschmalle@teotigraphix.com
 */
package org.teotigraphix.dx.patterns.manager
{

import flash.events.IEventDispatcher;

import org.teotigraphix.dx.core.ToolKitUtil;
import org.teotigraphix.dx.interfaces.IBehaviorLayer;
import org.teotigraphix.dx.interfaces.IBehaviorManager;
import org.teotigraphix.dx.interfaces.IComponentBehavior;
import org.teotigraphix.dx.patterns.manager.behavior.BehaviorManagerImpl;

/**
 * The static <code>IBehaviorManager</code> interface.
 * 
 * @author Michael Schmalle
 * @copyright Teoti Graphix, LLC
 * @date 08-03-08
 */
public class BehaviorManager
{
	include '../../core/Version.as'
		
	//--------------------------------------------------------------------------
	//
	//  IBehaviorManager API :: Methods
	//
	//--------------------------------------------------------------------------
	
	// TODO (mschmalle) Implement removeBehaviorLayer(component)
	
	//----------------------------------
	//  Layers
	//----------------------------------
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IBehaviorManager#createBehaviorLayer()
	 */
	public static function createBehaviorLayer(client:IEventDispatcher):IBehaviorLayer
	{
		return impl.createBehaviorLayer(client);
	}
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IBehaviorManager#getBehaviorLayer()
	 */
	public static function getBehaviorLayer(client:IEventDispatcher):IBehaviorLayer
	{
		return impl.getBehaviorLayer(client);
	}
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IBehaviorManager#hasBehaviorLayer()
	 */
	public static function hasBehaviorLayer(client:IEventDispatcher):Boolean
	{
		return impl.hasBehaviorLayer(client);
	}
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IBehaviorManager#registerBehaviorAPI()
	 */
	public static function registerBehaviorAPI(
		api:Class, clazz:Class):void
	{
		impl.registerBehaviorAPI(api, clazz);
	}
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IBehaviorManager#createBehavior()
	 */
	public static function createBehavior(
		client:IEventDispatcher, api:Class):IComponentBehavior
	{
		return impl.createBehavior(client, api);
	}
	
	//----------------------------------
	//  Behaviors
	//----------------------------------
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IBehaviorManager#registerBehavior()
	 */
	public static function registerBehavior(
		client:IEventDispatcher, api:Class, behavior:IComponentBehavior):void
	{
		impl.registerBehavior(client, api, behavior);
	}	
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IBehaviorManager#removeBehavior()
	 */
	public static function removeBehavior(
		client:IEventDispatcher, api:Class):IComponentBehavior
	{
		return impl.removeBehavior(client, api);
	}
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IBehaviorManager#hasBehavior()
	 */
	public static function hasBehavior(
		client:IEventDispatcher, api:Class):Boolean
	{
		return impl.hasBehavior(client, api);
	}
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IBehaviorManager#getBehavior()
	 */
	public static function getBehavior(
		client:IEventDispatcher, api:Class):IComponentBehavior
	{
		return impl.getBehavior(client, api);
	}
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IBehaviorManager#getBehaviors()
	 */
	public static function getBehaviors(client:IEventDispatcher):Array
	{
		return impl.getBehaviors(client);
	}
	
	//--------------------------------------------------------------------------
	//
	//  Private Class :: Variables
	//
	//--------------------------------------------------------------------------
	
	/**
	 * @private
	 */
	private static var implClassDependency:BehaviorManagerImpl;
	
	/**
	 * @private
	 */
	dx_internal static var _impl:IBehaviorManager;
	
	/**
	 * Returns the singleton implementation.
	 */
	private static function get impl():IBehaviorManager
	{
		if (!dx_internal::_impl)
		{
			dx_internal::_impl = IBehaviorManager(ToolKitUtil.getSingleton(
				"org.teotigraphix.dx.interfaces::IBehaviorManager"));
		}
		return dx_internal::_impl;
	}	
}
}